const state = {
  article: {
    title: "",
    img: null,
    content: "",
    category: "",
  },
};

const getters = {
  article: (state) => state.article,
};
const mutations = {
  setContent(state, article) {
    if (article) {
      state.article = article;
    } else {
      let article = {
        title: "",
        img: null,
        content: "",
        category: "",
      };
      state.article = article;
    }
  },
};
const actions = {
  async saveinLocal({ commit }, article) {
    window.localStorage.setItem("article", JSON.stringify(article));
  },
  getinLocal({ commit }) {
    return JSON.parse(window.localStorage.getItem("article"));
  },
  async deltoLocal({ commit }, article) {
    window.localStorage.removeItem("article");
    commit("setContent", null);
  },
};

export default {
  state,
  getters,
  mutations,
  actions,
};
